<template>
  <free-app
    bgType="image"
    :show-navbar="false"
    :customBodyStyle="'padding:0!important;'"
  >
    <view class="w-100vw h-100vh center flex-col gap-4">
      <image
        class="w-176rpx h-200rpx"
        src="/static/images/logo.png"
        mode="scaleToFill"
      />
      <!-- 
        v-if="userStore.userInfo && !userStore.userInfo?.phone"
      -->
      <button
        @getphonenumber="onGetphonenumber"
        open-type="getPhoneNumber"
        class="primary-btn w-[586rpx] h-[84rpx] font-500 text-size-3 rounded-[88rpx] mt-[74rpx]"
      >
        <view>手机号快捷登录</view>
      </button>
      <!-- <wd-loading
        v-if="!userStore.userInfo || userStore.userInfo?.phone"
        :size="40"
        color="#ffffff"
      /> -->
    </view>
  </free-app>
</template>

<script setup>
import { useUserStore } from "@/store/user";
import { onLoad } from "@dcloudio/uni-app";
import { checkWxPhoneNumber } from "@/api/user";

const userStore = useUserStore();

const onGetphonenumber = async (e) => {
  // console.log('获取用户手机号',e)
  console.log(e.detail.code); // 动态令牌
  console.log(e.detail.errMsg); // 回调信息（成功失败都会返回）
  console.log(e.detail.errno); // 错误码（失败时返回）
  const { data } = await checkWxPhoneNumber({
    code: e.detail.code,
  });
  // console.log("校验", data);
  userStore.refreshUserInfo();
  uni.reLaunch({
    url: "/pages/index/index",
  });
};

onLoad(() => {
  uni.reLaunch({
    url: "/pages/index/index",
  });
  // userStore.login().then(() => {
  //   if (!userStore.userInfo?.phone) return;
  //   uni.reLaunch({
  //     url: "/pages/index/index",
  //   });
  // });
});
</script>

<style lang="scss" scoped></style>
